# Maintainer: Sven-Hendrik Haase <sh@lutzhaase.com>
# Contributor: Slash <demodevil5[at]yahoo[dot]com>
# Contributor: J.W. Birdsong  <jwbirdsongATmailDOTcom>

pkgname=teamspeak3
pkgver=3.0.10.1
pkgrel=1
pkgdesc="TeamSpeak is software for quality voice communication via the Internet"
url="http://www.teamspeak.com/"
license=('custom')
depends=('qt4' 'libpulse')
arch=('i686' 'x86_64')
source=("http://teamspeak.gameserver.gamed.de/ts3/releases/${pkgver}/TeamSpeak3-Client-linux_x86-${pkgver}.run"
        "http://teamspeak.gameserver.gamed.de/ts3/releases/${pkgver}/TeamSpeak3-Client-linux_amd64-${pkgver}.run"
        'teamspeak3.desktop'
        'icon.xpm'
        'teamspeak3.launcher')
md5sums=('0ca4bbcda70630126b2e7c7531506d9f'
         'e6321e1f64c465eb6e54ecf65917c2b6'
         '98e987a42511f159fa2228f5e0bffed1'
         '19f103384e4c1a0aafc8fed44de0c87b'
         '170fcbb1b468ce4f3dba7ee3fb2a1c6d')

[[ "$CARCH" == "i686" ]] && _TSARCH='x86'
[[ "$CARCH" == "x86_64" ]] && _TSARCH='amd64'

package() {
  cd ${srcdir}

  # Create Destination Directories
  install -d ${pkgdir}/{usr/bin/,opt/}

  # Make Installer Executable
  chmod +x TeamSpeak3-Client-linux_${_TSARCH}-${pkgver}.run

  # Run Installer
  ./TeamSpeak3-Client-linux_${_TSARCH}-${pkgver}.run --noexec --target teamspeak3

  # Move Program Data to Package Directory
  mv ${srcdir}/teamspeak3/ ${pkgdir}/opt/

  # Remove Bundled Qt Libraries and Symlink system libraries to TS3 Directory
  rm ${pkgdir}/opt/teamspeak3/libQt*
  ln -s /usr/lib/libQtCore.so.4    ${pkgdir}/opt/teamspeak3/libQtCore.so.4
  ln -s /usr/lib/libQtGui.so.4     ${pkgdir}/opt/teamspeak3/libQtGui.so.4
  ln -s /usr/lib/libQtNetwork.so.4 ${pkgdir}/opt/teamspeak3/libQtNetwork.so.4

  # Fix FS#34190
  sed -i "/export QTDIR.*/d" ${pkgdir}/opt/teamspeak3/ts3client_runscript.sh
  sed -i "/export QT_PLUGIN_PATH*/d" ${pkgdir}/opt/teamspeak3/ts3client_runscript.sh
  
  # Fix FS#34189
  rm ${pkgdir}/opt/teamspeak3/qt.conf

  # Install Desktop File
  install -D -m644 $srcdir/teamspeak3.desktop ${pkgdir}/usr/share/applications/teamspeak3.desktop

  # Install Icon File
  install -D -m644 $srcdir/icon.xpm ${pkgdir}/usr/share/pixmaps/teamspeak3.xpm

  # Install Custom License
  install -D -m644 ${pkgdir}/opt/teamspeak3/LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE

  # Install Client Launcher
  install -D -m755 $srcdir/teamspeak3.launcher ${pkgdir}/usr/bin/teamspeak3
}
# vim:set ts=2 sw=2 et:
